package com.nowc.week.w103_ak;

import java.io.*;

public class b {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken(); int T = (int) in.nval;
        while (T-- > 0) {
            in.nextToken(); int n = (int) in.nval;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                in.nextToken(); a[i] = (int) in.nval;
            }
            boolean ans = false;
            for (int l = 0, r = 0; l < n; ) {
                int pre = a[l];
                while (a[r % n] >= pre) {
                    pre = a[r % n];
                    r++;
                    if ((r % n) == l) {
                        ans = true;
                        break;
                    }
                }
                if (ans) {
                    break;
                }
                l = r;
            }
            out.println(ans ? "YES" : "NO");
        }
        out.flush();
        out.close();
        br.close();
    }
}